# coding = utf-8
import os 
import re
def listyoudir(level, path):  
    for i in os.listdir(path):  
        if os.path.isdir(path + '\\' + i):  
            listyoudir(level+1, path + '\\' + i)
        else:
        	if i.endswith('.vm'):
        		fp = open(path + '\\' + i,"r")
        		data = fp.read().decode("gbk","ignore")
        		fp.close()
        		p = re.compile(r"\$csrfTokenHidden")
        		if p.search(data):        			
        			data = re.sub(r"\$csrfTokenHidden","#SHTML($csrfTokenHidden)",data)
        			wp = open(path + '\\' + i,"w")
        			wp.write(data.encode("gbk"))
        			wp.close()
        			print '--yes--'+path + '\\' + i
        		#else:
        			#print '--no--'+path + '\\' + i
        	
  
os.chdir('Z:\\zeus\\templates\\zeus\\chs')      	           
rootpath = os.path.abspath(".")
print rootpath  
listyoudir(0, rootpath) 